package com.ipc.common.util.gwl;

import org.springframework.validation.BindingResult;
import org.springframework.validation.FieldError;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Author 高万里
 */
public class NullJudgeUtil {

    private NullJudgeUtil(){};

    public static String nullJudge(BindingResult result){
        Map<String, String> map = new HashMap<>();
        List<FieldError> fieldErrors = result.getFieldErrors();
        for (FieldError fieldError : fieldErrors) {
            map.put(fieldError.getField(), fieldError.getDefaultMessage());
        }
        if (map.size() == 0) {
            return null;
        }
        return map.toString();
    }
}
